package com.smt.modules.app.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.smt.common.utils.*;
import com.smt.modules.app.annotation.Login;
import com.smt.modules.app.annotation.LoginUser;
import com.smt.modules.bus.entity.GradeEntity;
import com.smt.modules.bus.entity.MemberUserEntity;
import com.smt.modules.bus.service.GradeService;
import com.smt.modules.bus.service.RewardService;
import com.smt.modules.bus.vo.LevelTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 操作任务奖励
 *
 * @author zhangyi
 * @date 2018/10/17 12:32
 */
@RestController
@RequestMapping("/app/reward")
@Api(tags = {"AppRewardController"}, description = "日常奖励操作，账单表(客户端接口)")
public class AppRewardController {

    @Resource
    private RewardService rewardService;

    @Resource
    private GradeService gradeService;

    @Resource
    private ResourceLoader resourceLoader;
    /**
     *   获取该用户的任务列表
     *   返回该用户未完成的所有主线任务（仅有一次）
     *   每日一次的支线任务
     *   一日一次的任务完成或者是子任务完成s
     *
     * @return
     */
    @Login
    @GetMapping("/tasks")
    @ApiOperation(value = "获取该用户的任务列表",httpMethod = "GET")
    public R getMemberTaskList(@LoginUser MemberUserEntity memberUserEntity){
        return rewardService.getMemberTaskList(memberUserEntity);
    }

    /**
     * 用户领取奖励
     *
     * @param memberUserEntity
     * @return
     */
    @Login
    @PostMapping("/makeTask")
    @ApiOperation(value = "日常操作奖励",httpMethod = "POST")
    public R makeTask(@RequestBody LevelTaskVo levelTaskVo, @LoginUser MemberUserEntity memberUserEntity){
        return rewardService.makeTask(levelTaskVo,memberUserEntity);
    }

    /**
     * 用户等级展示
     *
     * @return
     */
    @Login
    @GetMapping("/showLevel")
    @ApiOperation(value = "用户等级展示",httpMethod = "GET")
    public R showLevel(@RequestAttribute("userId") Long userId) throws Exception {
        GradeEntity gradeEntity = gradeService.selectOne(new EntityWrapper<GradeEntity>()
                .eq("member_id", userId));
        return R.ok().put("level",gradeEntity);
    }
    
}
